<template>
  <ea-dialog
      v-bind="$attrs"
      v-on="$listeners"
      width="400px"
      ref="elDialog"
      :title="dietitle"
      :type="type"
      @submit="submit"
      @reset="$refs.form.resetFields()"
      @closed="onClosed"
  >
    <el-form ref="form" :model="singleData" :rules="rules" label-width="100px">
      <el-form-item label="选择学校" prop="schoolcode">
        <el-select
            v-model="singleData.schoolcode"
            @change="getDept"
            filterable
            placeholder="请选择学校"
        >
          <el-option
              v-for="item in schoolList"
              :key="item.value"
              :label="item.name"
              :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择院系" prop="deptcode">
        <el-select v-model="singleData.deptcode" placeholder="请选院系">
          <el-option
              v-for="item in deptList"
							ref="deptValue"
              :key="item.value"
              :label="item.name"
              :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级名称" prop="organizename">
        <el-input v-model="singleData.organizename" maxlength="10"></el-input>
      </el-form-item>
      <el-form-item label="班级描述" prop="description">
        <el-input v-model="singleData.description"></el-input>
      </el-form-item>
    </el-form>
  </ea-dialog>
</template>

<script>
import editAndAdd from "@/mixins/business/editAndAdd";
import schoolDeptClassSelection from "@/mixins/business/schoolDeptClassSelection"

export default {
  name: "EaClass",
  mixins: [editAndAdd, schoolDeptClassSelection],
	props:{
		dietitle:String,
	},
  data() {
    return {
      moduleName: "班级",
      singleData: {
        schoolcode: "",
        description: "",
        organizecode: null,
        organizename: "",
        deptcode: ""
      },
      rules: {
        schoolcode: {required: true, message: "请选择学校！"},
        deptcode: {required: true, message: "请选择院系！"},
        organizename: {required: true, message: "请输入班级名称！"}
      }
    };
  },
  methods: {
    handle() {
      if (this.type === "add") this.singleData.organizecode = null;
      return this.axios.post("/sys/class/SubmitClass", this.singleData);
    },
    onClosed() {
      this.deptList.splice(0)
      this.end();
    }
  }
};
</script>

<style scoped></style>
